import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class DiscountViewModel extends ChangeNotifier {
  List<FlSpot> listFlSpot = [FlSpot(0, 0)];
  List time = ["暂无数据"];

  String titleText = "成绩曲线";

  Map<String, dynamic> mapScore;
  BuildContext me;

  DiscountViewModel(this.me, this.mapScore);

  initView() {
    print(mapScore);
    if (mapScore != null) {
      titleText = mapScore["subject"] ?? "";
      List score = mapScore["score"];
      if (score.length == 0 || score == null) {
        return;
      }
      if (mapScore["time"] == null) {
        return;
      }
      listFlSpot.clear();
      time.clear();
      if (score.length > 8) {
        for (int i = 0; i < 8; i++) {
          listFlSpot.add(FlSpot(double.parse("$i"), (score[i]) * 0.05));
        }
      } else {
        for (int i = 0; i < score.length; i++) {
          listFlSpot.add(FlSpot(double.parse("$i"), (score[i]) * 0.05));
        }
      }
      time = mapScore["time"];
      notifyListeners();
    }
  }
}
